<template>
	<view>
		<template v-for="(item, index) in list">
			<action-card :data="item" v-if="item.permission.indexOf(userInfo.role_name) !==-1" :key="index">
			</action-card>
		</template>
		<!-- 
		<u-upload ref="uUPload" :before-upload="beforeUpload" :http-request="httpRequest" @on-uploaded="onUploaded"
			@on-success="onSuccess" @on-progress="onProgress"></u-upload> -->

	</view>
</template>

<script>
	import ActionCard from "../../components/ActionCard.vue";
	export default {
		components: {
			ActionCard
		},
		data() {
			return {
				list: [{
						icon: 'file-text-fill',
						title: '需求单',
						url: '/pages/carrier/demandList',
						isBadge: true,
						num: 0,
						permission: ['carrier']
					},
					{
						icon: 'car-fill',
						title: '运输单',
						url: '/pages/carrier/transportList',
						isBadge: true,
						num: 0,
						permission: ['carrier', 'driver']
					},
					{
						icon: 'coupon-fill',
						title: '询价单',
						url: '/pages/carrier/inquiryIndex',
						isBadge: true,
						num: 0,
						permission: ['carrier']
					},
				]
			}
		},
		onShow() {

		},
		methods: {
			async beforeUpload(index, list) {
				// 返回一个promise
				return true
				console.log(list);
				this.$u.api.common.uploadFile({
					file: list[0].url
				}).then(res => {
					// resolve()之后，将会进入promise的组件内部的then回调，相当于返回true
					// resolve();
					console.log(res);
				}).catch(err => {
					// reject()之后，将会进入promise的组件内部的catch回调，相当于返回false
				})
			},
			httpRequest(data) {
				// const {file, name, success, progress, error} = data 里面的所有属性和方法
				console.log('自定义上传方法：httpRequest', data);
				this.$u.api.common.uploadFile(data.file.url, {
					getTask: (task, config) => {
						task.onProgressUpdate(res => {
							data.progress(res)
						})
					}
				}).then(res => {
					data.success(res);
				}).catch(err => {
					data.error(err);
				})
			},
			onUploaded(lists, name) {
				console.log('onUploaded', lists, name);
			},
			onSuccess(data, index, lists, name) {
				console.log('onSuccess', data, index, lists, name);
			},
			onProgress(res, index, lists, name) {
				// console.log('onProgress', res, index, lists, name);
			}
		}
	}
</script>

<style>

</style>
